<?php

class PaymentBidPack extends PaymentData {

	public $bidPackId;
	public $bidPackPrice;
	public $amount;
	public $bonus;
	public $bidPackTitle;
	
	public function __construct(){
		$this->setName('bidPack');
	}
	
	public function getBidPackInfo($bidpackid){
		$this->bidPackId = $bidpackid;
		// $bidPackInfo = Products::model()->find('id = :bidpackid',array(':bidpackid'=>$this->bidPackId));
		$bidpack= ProductInfo::model()->findAll('id = :bidpackid',array(':bidpackid'=>$this->bidPackId));
		$bidPackInfo = ProductParame::model()->findAll('product_id = :bidpackid',array(':bidpackid'=>$this->bidPackId));

		$bidPackbids = $bidPackInfo[0];
		$bidPackbonus = $bidPackInfo[1];
		$bidpackfee = ProductFee::model()->findAll('product_id = :bidpackid and fee_name="value_price"',array(':bidpackid'=>$this->bidPackId));
		$bidpackbids = ProductFee::model()->findAll('product_id = :bidpackid and fee_name="bids"',array(':bidpackid'=>$this->bidPackId));
		$bidPackbonus = ProductFee::model()->findAll('product_id = :bidpackid and fee_name="bonus"',array(':bidpackid'=>$this->bidPackId));
		$this->bidPackPrice = $bidpackfee[0]->fee_value;
		$this->amount = round($bidpackbids[0]->fee_value);
		if(!empty($bidPackbonus)){
			$this->bonus = $bidPackbonus[0]->fee_value;
		}else{
			$this->bonus = 0;
		}
		$this->bidPackTitle = $bidpack[0]->title;
		return $this;
	}
	
	public function vaild(){
		if (empty($this->bidPackId)){
			$this->setErrorMessage('bidPackId','bidPackId NO');
		}		
		return $this->vaild;
	}
	
	public function toArray(){
		return array(
				'bidPackId' 	=> $this->bidPackId,
				'bidPackPrice'	=> $this->bidPackPrice,
				'amount'	=> $this->amount,
				'bonus'	=> $this->bonus,
				'bidPackTitle' => $this->bidPackTitle,
		);
	}
}
